import { FactoryState } from "GameLoop/WorldState/EntityManager/Entitys/room/factory/constants";
import { State } from "framework/FSM/AState";

/**
 * 完成
*/
export class FactoryComplete<T extends IStateArg<Room>> extends State<T>
{

    public getActions(arg:T):Action[]
    {
        const actions:Action[] = [];
        const task = arg.entity.getTaskByType("factory")[0] ;
        
        const core = arg.entity.getEntity("CoreEntity");
        // const toptask = FactoryTaskHelper.Top(task.arg);
        const factory = core.Factory;
        if(core.Terminal&& factory && task.data.arg.ProduceList.length == 0)
        {
            const storecount = factory.store.getUsedCapacity(task.data.arg.TopTask.target);
            if(storecount)
            {
                const transportkey = core.transferOutTask(factory ,{resourceType:task.data.arg.TopTask.target as ResourceConstant,amount:storecount});
                if(transportkey)
                {
                    task.data.arg.transportKey = transportkey;
                }
            }
            
            task.data.arg.state= FactoryState.complete
            // arg.entity.transferOutTask({ResourceType:task.arg.TopTask.target as ResourceConstant,Amount:storecount});
            // arg.entity.popTask();
            core.log("info","生产完成 清理任务",JSON.stringify(task))
            // global.Log.Info(`生产完成 清理任务 ${JSON.stringify(task) } core:task${arg.entity.Agent<CoreEntity>().taskCount}`);
        }
        return actions;
    }
}
